const path = require('path')
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const productionGzipExtensions = ['js', 'css'];
module.exports = {
	publicPath: '/wygfdp', // 部署应用时的根路径(默认'/'),也可用相对路径(存在使用限制:history模式 和 多页面应用)
	assetsDir: "static",
	outputDir: 'wygfdp',
	productionSourceMap: false, // 生产环境是否生成 sourceMap 文件
	devServer: { // 环境配置
		host: '0.0.0.0',
		port: 8001,
		https: false,
		hotOnly: false,
		open: false, //配置自动启动浏览器
		proxy: { // 配置多个代理(配置一个 proxy: 'http://localhost:4000' )
			'/zkd-api': {
				target: 'https://dr.kjt.zj.gov.cn:8888',
				changeOrigin: true,
				ws: true,
				pathRewrite: {
					'^/zkd-api': '/zkd-api'
				}
			},
		}
	},
	pluginOptions: { // 第三方插件配置
		// ...
	},
	css: {
		sourceMap: false, // 开启 CSS source maps?
		loaderOptions: {
			less: {
				lessOptions: {
					javascriptEnabled: true,

				}
			}
		}
	},
	// 配置webpack
	configureWebpack: config => {
		// 开启gzip压缩

		config.plugins.push(new CompressionWebpackPlugin({
			algorithm: 'gzip',
			test: /\.js$|\.html$|\.json$|\.css/,
			threshold: 10240,
			minRatio: 0.8
		}));
		// 开启分离js
		config.optimization = {
			runtimeChunk: 'single',
			splitChunks: {
				chunks: 'all',
				maxInitialRequests: Infinity,
				minSize: 20000,
				cacheGroups: {
					vendor: {
						test: /[\\/]node_modules[\\/]/,
						name(module) {
							// get the name. E.g. node_modules/packageName/not/this/part.js
							// or node_modules/packageName
							const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
							// npm package names are URL-safe, but some servers don't like @ symbols
							return `npm.${packageName.replace('@', '')}`
						}
					}
				}
			}
		};
		// 取消webpack警告的性能提示
		config.performance = {
			hints: 'warning',
			//入口起点的最大体积
			maxEntrypointSize: 50000000,
			//生成文件的最大体积
			maxAssetSize: 30000000,
			//只给出 js 文件的性能提示
			assetFilter: function (assetFilename) {
				return assetFilename.endsWith('.js');
			}
		}
	},
};